﻿namespace HZY.Api.Admin.Controllers.Systems;

/// <summary>
/// 数据字典控制器
/// </summary>
[ControllerDescriptor(MenuId = "23", DisplayName = "数据字典")]
public class SysDictionaryController(IServiceProvider serviceProvider)
    : AdminControllerBase<SysDictionaryService>(serviceProvider)
{
    /// <summary>
    /// 获取列表
    /// </summary>
    /// <param name="search"></param>
    /// <returns></returns>
    [ActionDescriptor(DisplayName = "查看列表")]
    [HttpPost]
    public async Task<List<SysDictionaryTreeDto>> FindListAsync([FromBody] SysDictionary search)
    {
        return await Service.FindListAsync(search);
    }

    /// <summary>
    /// 获取字典树
    /// </summary>
    /// <returns></returns>
    [ActionDescriptor(DisplayName = "获取字典树")]
    [HttpGet()]
    public async Task<List<SysDictionaryTreeDto>> GetDictionaryTreeAsync()
    {
        return await Service.GetDictionaryTreeAsync();
    }

    /// <summary>
    /// 根据编码获取 字典集合
    /// </summary>
    /// <param name="code"></param>
    /// <returns></returns>
    [HttpGet("{code}")]
    public Task<List<SysDictionaryTreeDto>> GetDictionaryTreeByCodeAsync([FromRoute] string code)
    {
        return Service.GetDictionaryTreeByCodeAsync(code);
    }

    /// <summary>
    /// 根据编码获取 字典集合
    /// </summary>
    /// <param name="code"></param>
    /// <returns></returns>
    [HttpGet("{code}")]
    public Task<List<SysDictionaryDto>> GetDictionaryByCodeAsync([FromRoute] string code)
    {
        return Service.GetDictionaryByCodeAsync(code);
    }
}